//
//  CustomTabItem.h
//
//  使用方法:
//      数据源:
//        NSMutableArray* data = [[NSMutableArray alloc]initWithCapacity:0];
//        for (NSInteger i=0; i<5; ++i)
//        {
//            NSString* tmp_title = [NSString stringWithFormat:@"测试%d", i];
//            [data addObject:tmp_title];
//        }
//        Model_DataSource* dataSource = [[Model_DataSource alloc]init];
//        [dataSource setData:data];
//        [data release];
//      或:
//        NSMutableArray* data = [[NSMutableArray alloc]initWithCapacity:0];
//        NSString *key_data = @"title";
//        for (NSInteger i=0; i<5; ++i)
//        {
//            NSString* tmp_title = [NSString stringWithFormat:@"n测试%d", i];
//            NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:tmp_title, key_data,nil];
//            [data addObject:dic];
//            [dic release];
//        }
//        Model_DataSource* dataSource = [[Model_DataSource alloc]init];
//        dataSource.data_type = DATA_TYPE_DICTIONARY;
//        dataSource.key_data = key_data;
//        [dataSource setData:data];
//        [data release];
//      视图创建
//        CGRect tablist_frame = CGRectMake(0, 100, self.view.frame.size.width, 40);
//        tabList = _ALLOC_OBJ_WITHFRAME_(CustomTabList, tablist_frame);
//        tabList.tabList_delegate = self;
//        [self.view addSubview:tabList];
//        [tabList release];
//        tabList.dataSource = dataSource;
//        [dataSource release];
//  如果需要点击事件则需要实现以下protocol
//        - (void)doTabItemClick:(CustomTabItem*)sender
//        {
//
//            NSLog(@"itemIndex:%d", sender.nindex);
//        }
//
//  Created by zhangtie on 13-4-3.
//  Copyright (c) 2013年 zhangtie. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "QBDataSourceItem.h"

#define ITEM_PADDINGBOTTOM  1.5

#define ITEM_PADDINTLEFT    2.0f

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 60000
#ifndef NSUITextAlignment
#define NSUITextAlignment NSTextAlignment
#endif
#ifndef NSUILineBreakMode
#define NSUILineBreakMode NSLineBreakMode
#endif
#else
#ifndef NSUITextAlignment
#define NSUITextAlignment UITextAlignment
#endif
#ifndef NSUILineBreakMode
#define NSUILineBreakMode UILineBreakMode
#endif
#endif

typedef enum _NOTE_TYPE
{
    NOTE_TYPE_LEFT  = 0,
    NOTE_TYPE_RIGHT = 1,
}NOTE_TYPE;

@interface CustomTabItem_DataItem : DataItem
{
    NSString    *_key_data;
}

@property(nonatomic, copy)NSString *key_data;

@end

@protocol CustomTabItem_Delegate <NSObject>

@optional
- (void)doTabItemClick:(id)sender;

@end

@interface CustomTabItem : UIView
{
@private
    UILabel    *_lab_title;
    
    TABITEM_STATE _state;
    NSInteger   _nindex;        //索引
    UIColor     *_color_selected;
    UIColor     *_color_normal;
    UIColor     *_color_textSelected;
    UIColor     *_color_textNormal;
    
    
    id<CustomTabItem_Delegate> _delegate;
}

@property(nonatomic, assign, readonly)NSInteger nindex;
@property(nonatomic, retain)UIColor* color_selected;
@property(nonatomic, retain)UIColor* color_normal;
@property(nonatomic, retain)UIColor* color_textSelected;
@property(nonatomic, retain)UIColor* color_textNormal;
@property(nonatomic, readonly, assign)TABITEM_STATE state;
@property(nonatomic, assign)id<CustomTabItem_Delegate> tabItem_delegate;
@property(nonatomic, retain)UIImageView *background;
@property(nonatomic, retain)UIView      *bg_background;
@property(nonatomic, assign)CGFloat item_horizon_margin;

- (NSString*)title;
- (void)setIndex:(NSInteger)index;
- (void)setFontSize:(CGFloat)font_size;
- (void)setAlign:(NSUITextAlignment)align;
- (void)setTabItemTitle:(NSString*)str_title;
- (void)changeForState:(TABITEM_STATE)state;

@end


#define DATA_TYPE_DEFAULT   DATE_TYPE_VALUE

@protocol CustomTabList_Delegate <NSObject>

@optional
- (void)doTabItemClick:(id)sender withItem:(CustomTabItem*)item;

@end

@interface CustomTabList : UIView<CustomTabItem_Delegate, UIScrollViewDelegate>
{
    UIScrollView    *_view_scroll;
    
    LAYOUT_TYPE     _layout_type;
    
    NSMutableArray  *_dataSource;
    
    NSInteger       _ndefaultSelectedIndex;        //当前选中项
    
    //视图容器
    NSMutableArray  *_container;
    
    id<CustomTabList_Delegate> _delegate;
    
    UIImageView     *_imageSign;
    
    UIImageView     *_imageNoteSign;        //左右提示箭头
    
    BOOL            _changeAnimal;       //切换时候是否启用动画
    
    CGFloat         _itemSpace;
    
@protected
    NSInteger       _ncurrentSelectedIndex;
}

@property(nonatomic, assign)LAYOUT_TYPE layout_type;
@property(nonatomic, retain)NSMutableArray *dataSource;
@property(nonatomic, assign)NSInteger ndefaultSelectedIndex;
@property(nonatomic, retain)UIColor* color_selected;
@property(nonatomic, retain)UIColor* color_normal;
@property(nonatomic, retain)UIColor* color_textSelected;
@property(nonatomic, retain)UIColor* color_textNormal;
@property(nonatomic, assign)CGFloat itemSpace;                  //间距,默认是0
@property(nonatomic, assign)BOOL    isCoverage;                 //宽度是否均分,默认均分
@property(nonatomic, assign)CGFloat itemWidth;                  //isCoverage为NO时候有用
@property(nonatomic, retain)UIImage *bgimage_selected;
@property(nonatomic, retain)UIImage *bgimage_normal;
@property(nonatomic, assign)CGFloat padding_top;                //default is 0
@property(nonatomic, assign)CGFloat padding_right;              //default is 0
@property(nonatomic, assign)CGFloat padding_bottom;             //default is ITEM_PADDINGBOTTOM
@property(nonatomic, assign)CGFloat item_horizon_margin;        //default is ITEM_PADDINTLEFT, item中title水平偏移
@property(nonatomic, assign)CGFloat font_size;
@property(nonatomic, assign)BOOL    changeAnimal;               //切换时候是否启用动画
@property(nonatomic, assign)BOOL    isNeedDefaultSelectedEvent; //default is YES
@property(nonatomic, assign)id<CustomTabList_Delegate> tabList_delegate;
@property(nonatomic, assign, readonly)NSInteger       ncurrentSelectedIndex;

- (void)initContainer;
- (void)initScrollView;
- (void)toNextResponderWithObject:(id)parm;
- (NSString*)getTitleForItem:(CustomTabItem_DataItem*)item;

/**************************item相关********************************/
//对title只支持读接口
- (NSString*)titleAtIndex:(NSInteger)index;
- (void)setFontSizeAtIndex:(NSInteger)index font_size:(CGFloat)font_size;
- (void)setAlignAtiIndex:(NSInteger)index align:(NSUITextAlignment)align;

/**************************item相关********************************/

- (void)setBackgroundImage:(UIImage*)bg_image inFrame:(CGRect)bg_frame;

//- (CGFloat)getItemWidthForDefaultWidth:(CGFloat)default_width withTextSize:(CGSize)text_size;

@end